#ifndef __DRV_SDCARD_H_
#define __DRV_SDCARD_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include "system.h"

enum
{
    SDCARD_STA_READY = 1,           //
    SDCARD_STA_IDENTIFICATION,      //identification
    SDCARD_STA_STANDBY,             //standby
    SDCARD_STA_TRANSFER,            //transfer
    SDCARD_STA_SENDING,             //sending an operation
    SDCARD_STA_RECEIVING,           //receiving operation information
    SDCARD_STA_PROGRAMMING,         //programming
    SDCARD_STA_DISCONNECTED,        //disconnected
    SDCARD_STA_ERROR = 0xFF,
};

typedef struct 
{
    uint32_t card_type;
    uint32_t card_version;
    uint32_t card_speed;
    uint32_t class;
    uint32_t rel_card_addr;
    uint32_t block_nbr;
    uint32_t block_size;
    uint32_t block_logical_nbr;
    uint32_t block_logical_size;
} drv_sdcard_info_obj;

typedef struct 
{
    uint8_t manufacturer_id;    //制造商ID
    uint16_t oem_appli_id;      //
    uint32_t prod_name_1;
    uint8_t prod_name_2;
    uint8_t prod_rev;           //产品修订版
    uint32_t prod_sn;           //产品序列号
    uint16_t manufact_date;     //制造日期
} drv_sdcard_cid_obj;


/* export func */

void drv_sdcard_init(void);
void drv_sdcard_deinit(void);

uint8_t drv_sdcard_is_exist(void);
uint8_t drv_sdcard_get_card_info(drv_sdcard_info_obj *info);
uint8_t drv_sdcard_get_card_cid(drv_sdcard_cid_obj *cid);
uint8_t drv_sdcard_get_state(void);

uint8_t drv_sdcard_erase(uint32_t addr_start, uint32_t addr_end);
uint8_t drv_sdcard_read_blocks(uint32_t addr, uint8_t *pbuf, uint32_t blocks, uint32_t timeout);
uint8_t drv_sdcard_write_blocks(uint32_t addr, uint8_t *pbuf, uint32_t blocks, uint32_t timeout);
uint8_t drv_sdcard_read_blocks_dma(uint32_t addr, uint32_t *pbuf, uint32_t blocks);
uint8_t drv_sdcard_write_blocks_dma(uint32_t addr, uint32_t *pbuf, uint32_t blocks);


#ifdef __cplusplus
}
#endif

#endif // __DRV_SDCARD_H_
